package com.hualan.sfzy.controller.course;

import com.hualan.sfzy.entity.CourseClassification;
import com.hualan.sfzy.service.course.CourseClassificationService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/courseClassification")
public class CourseClassificationController {
    @Autowired
    private CourseClassificationService courseClassificationService;

    @PostMapping
    public Result add(@RequestBody CourseClassification entity){
        int result = courseClassificationService.add(entity);
        if (result>0)
            return Result.success(result);
        return Result.error("添加失败");
    }

    @GetMapping
    public Result find(){
        List<CourseClassification> list = courseClassificationService.find();
        if (list!=null)
            return Result.success(list);
        return Result.error("查询失败");
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        CourseClassification courseClassification = courseClassificationService.findById(id);
        if (courseClassification!=null)
            return Result.success(courseClassification);
        return Result.error("查询失败");
    }
    @PostMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           @RequestBody(required = false) CourseClassification entity){
        Map<String,Object> map = courseClassificationService.findPage(pageNum,pageSize,entity);
        if (map!=null)
            return Result.success(map);
        return Result.error("查询失败");
    }
    @DeleteMapping("/{id}")
    public Result remove(@PathVariable Integer id){
        int result = courseClassificationService.remove(id);
        if (result>0)
            return Result.success(result);
        return Result.error("删除失败");
    }
    @DeleteMapping("/batch")
    public Result removeBatch(Integer[] ids){
        int result = courseClassificationService.removeBatch(ids);
        if (result>0)
            return Result.success(result);
        return Result.error("删除失败");
    }
    @PutMapping
    public Result edit(@RequestBody CourseClassification entity){
        int result = courseClassificationService.edit(entity);
        if (result>0)
            return Result.success(result);
        return Result.error("修改失败");
    }





}
